package com.unionftech.common.recaptcha.aliyun

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
import android.webkit.WebSettings
import android.webkit.WebView

class AliyunCaptchaWebView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : WebView(context, attrs, defStyleAttr) {

    init {
        setBackgroundColor(Color.parseColor("#80000000"))
        //启动JavaScript
        settings.javaScriptEnabled = true
        settings.domStorageEnabled = true
        settings.blockNetworkImage = false
        //设置屏幕自适应
        settings.useWideViewPort = true
        settings.loadWithOverviewMode = true
        settings.cacheMode = WebSettings.LOAD_NO_CACHE
        overScrollMode = View.OVER_SCROLL_NEVER
        setOnTouchListener { _, _ ->
            // 返回false表示取消原生滑动
            return@setOnTouchListener false
        }
    }
}